{% load widget_tweaks %}
<script type="text/javascript">
	$('#custom_setpoint_div').hide()
	$('#setpoint_radio input:radio').change(function () {
		$('#custom_setpoint_div').hide()
		if ($('#fixed_setpoints').is(':checked') || $('#custom_fixed_setpoints').is(':checked')){
				buildSetpointTree('fixed')
				$('#loadSearchedSetpoints').attr('disabled','disabled')
			}
		else {buildSetpointTree(); $('#loadSearchedSetpoints').removeAttr('disabled');}
		if ($('#custom_fixed_setpoints').is(':checked')){
			$('#custom_setpoint_div').show()
		}
	});
	$('#loadSearchedPoints').click(function(){
		searchPaths('points')
    })
    $('#loadSearchedSetpoints').click(function(){
		searchPaths('setpoints')
    })
    function searchPaths(type){
    	var searchExpression = $('#searchExpressionText').val()
    	//if (searchExpression.search('CBE Toolkit') > 0){}
    	var query = 'select distinct Path where Path like \'' + searchExpression + '\'';
    	$.post("/backend/api/query/", query, 
	        function(data) {
	        	data = data.sort()
	        	var childrenL = [type];
	        	for (var i=0; i<data.length;i++){
	     			childrenL.push({"data":data[i],"attr": {"class": "jstree-drop"}})
	        	}
	        	buildSetpointTree(false, childrenL)
	        })
    }
</script>
<h6>Instructions</h6>
<p><small>There are three ways to define setpoints and points (e.g. zone temperature or pressure) to compare. (1) Drag corresponding points 
	and setpoints on the left to the appropriate folder on the right. <b>Order matters.</b> (e.g. the first point is subtracted from the first setpoint) (2) Load setpoints and points using an expression to search by path name. This method
	only works with BMS data, not CBE Toolkit devices. (3) load an existing mapping.</small></p>
<h6>Setpoint options</h6>
<div id="setpoint_radio">
<label class="radio"><input id="choose_setpoints" name="setpoints" type="radio" value="choose" checked>Choose setpoints</label>
<label class="radio"><input id="fixed_setpoints" name="setpoints" type="radio" value="fixed">Use temperature setpoints from Building page</label>
<label class="radio"><input id="custom_fixed_setpoints" name="setpoints" type="radio" value="custom">Use custom fixed setpoints.</label>
</div>
<div id="custom_setpoint_div" style="margin-left: 18px">
	<input type="text" class="span1" id="custom_setpoint_low">&nbsp;low
	<input type="text" class="span1" id="custom_setpoint_high">&nbsp;high (optional)
</div>
<h6>Load setpoints and points from regular expression path search</h6>
<span>Enter a path expression to search. E.g. /Siemens/SDH.PXCM-04/SDH/%S1-%/CTL_STPT</span><br>
<input type="text" class="span5" id="searchExpressionText"><br>
<input style="margin-bottom: 5px" class="btn btn-small" type="button" value="Load points" id="loadSearchedPoints">
<input style="margin-bottom: 5px" class="btn btn-small" type="button" value="Load setpoints" id="loadSearchedSetpoints">
<label style="margin-bottom: 5px" class="checkbox inline"><input style="margin-bottom: 5px" type="checkbox" id="appendPoints">Append to current list</label><br>
<h6>Load saved setpoints and points</h6>
<form class="form-inline" method="post" action="" style="display: inline" id="configDrop">
	{{ configFileFD.name|add_class:"form-inline span2"}}
	<input class="btn btn-small" type="submit" value="Load" id="loadSetpoints" onclick="buildSetpointTree(true,false); return false;">&nbsp;&nbsp;&nbsp;
</form>
<form class="form-inline" method="post" action="" style="display: inline" id="configFile">
	<input type="hidden" name="projectId" id="projectId" \>
	<input type="hidden" name="configFile" value="1" \>
	{{ configFileF.name|add_class:"form-inline span2"}}&nbsp;
	<input class="btn btn-small" type="submit" value="Save" id="saveSetpoints" onclick="saveSetpointTree(true); return false;">
</form>
<div id="success" style="display: inline"></div>
